//
//  TXYVideoThumbCacheManger.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/9/1.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "TXYVideoThumbCacheManger.h"

@interface NSURL (PathFileGet)
- (NSString *)pathFile;
@end

@implementation NSURL (PathFileGet)

- (NSString *)pathFile{
    return [[self pathComponents] lastObject];
}

@end

@interface TXYVideoThumbCacheManger ()

/**
 *  @{@"URLString":UIImage};
 */
@property (nonatomic, strong) NSMutableDictionary * cacheList;
@end
@implementation TXYVideoThumbCacheManger


- (id)init{
    self = [super init];
    
    if(self)
    {
    self.cacheList = [[NSMutableDictionary alloc] init];
    }
    
    return self;
}

+ (TXYVideoThumbCacheManger *)sharedManger{
    static dispatch_once_t onceToken;
    static TXYVideoThumbCacheManger *cacheManger;
    dispatch_once(&onceToken, ^{
        cacheManger = [[TXYVideoThumbCacheManger alloc] init];
    });
    
    return cacheManger;
}

+ (BOOL)hasCache:(NSURL *)urlStr{
    if([[[TXYVideoThumbCacheManger sharedManger] cacheList] objectForKey:[urlStr absoluteString]])
        return YES;
    
    return NO;
}

+ (UIImage *)getCachedThumbImage:(NSURL *)cachedImage{
    return [[[TXYVideoThumbCacheManger sharedManger] cacheList] objectForKey:[cachedImage absoluteString]];
}

+ (void)cacheThumbImage:(NSURL *)cachedURL image:(UIImage *)cachedImage{
    [[[TXYVideoThumbCacheManger sharedManger] cacheList] setObject:(cachedImage?cachedImage:@"") forKey:[cachedURL absoluteString]];
}
@end
